$(function(){
	$("#pro_bro_datagrid").datagrid({    
	    url:'repertory_manager/allSubProInfo.do', 
	    loadMsg:'数据加载中···',
	    fit:'true',
	    idField:'id',
	    pagination:true,
	    checkOnSelect : true,
		selectOnCheck : true,
		fitColumns:true,//允许表格自动缩放,以适应父容器  
	    columns:[[
	    {
			field : "ck",
			checkbox : true
		},
		{
			field : "id",
			hidden : true
		},     
	    {
			field:'pro_no',
			title:'商品编码',
			width:260,
			align:'center',
	    },     
	    {
			field:'pro_name',
			title:'商品名称',
			width:220,
			align:'center',
	    },    
	    {
	    	field:'customer_no',
	    	title:'客户编码',
	    	width:240,
	    	align:'center'
	     },
	     {
	    	 field:'warehouse',
	    	 title:'有效仓库',
	    	 width:240,
	    	 align:'center'
	    },{
	    	 field:'location',
	    	 title:'区位',
	    	 width:220,
	    	 align:'center'
	    },{
	    	 field:'loc_no',
	    	 title:'库位号',
	    	 width:220,
	    	 align:'center'
	    },{
	    	field:'size',
	    	title:'尺寸',
	    	width:220,
	    	align:'center',
	        formatter: function(value,row,index){
	        	return row.length+"x"+row.width+"x"+row.height;
	    }},{
	    	 field:'weight',
	    	 title:'重量',
	    	 width:150,
	    	 align:'center'
	    },{
	    	 field:'pre_postage',
	    	 title:'预估邮费',
	    	 width:120,
	    	 align:'center'
	    },{
	    	 field:'pro_number',
	    	 title:'数量',
	    	 width:120,
	    	 align:'center'
	    },{
	    	 field:'image_name',
	    	 title:'图片',
	    	 width:120,
	    	 align:'center',
	    	 formatter:function(value,row,inedex){
	    		 if(value==null || value==""){
	    			 return "未上传";
	    		 }else{
	    			 return "<a target='_blank' href="+$("input[name='filePath2']").val()+value+">点击查看</a>"; 
	    		 }
	    		 
	    	 }
	    },{
   	    	field:'create_tm',
   	    	title:'入库时间',
   	    	width:270,
   	    	align:'center',
   	        formatter: function(value,row,index){
   	        	return getTime(value);
   	        }}
	    ]],
	    fitColumns:true,
	    toolbar:'#sub_pro_tb'
	});  	
});	
function getTime(old) {
	var date = new Date(old);
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	if (month < 10)
		month = "0" + month;
	var day = date.getDate();
	if (day < 10)
		day = "0" + day;
	var hour = date.getHours();
	if (hour < 10)
		hour = "0" + hour;
	var minute = date.getMinutes();
	if (minute < 10)
		minute = "0" + minute;
	var seconds = date.getSeconds();
	if (seconds < 10)
		seconds = "0" + seconds;
	var newDate = year + "-" + month + "-" + day + " " + hour + ":" + minute
			+ ":" + seconds;
	return newDate;
}
function queryPro(){
	$("#pro_bro_datagrid").datagrid({
		queryParams: {
			customerNo: $("input[name='putCustomerNo']").val()
		}
	});
}
function resetPro(){
	$("input[name='putCustomerNo']").val("");
	queryPro();	
}

function delSubPro(){
	var rows = $("#pro_bro_datagrid").datagrid('getChecked');
	if (rows && rows.length > 0) {
		parent.$.messager.confirm('提示', '确定删除该商品信息?', function(r) {
			if (r) {
				var ids = [];
				for ( var i = 0; i < rows.length; i++){
					ids.push(rows[i].id);
				}
				$.ajax({
					url : "repertory_manager/delSubProInfo.do?ids="+ids.join(","),
					dataType : "json",
					success : function(data) {
						if (data && data.success) {
							parent.$.messager.alert('提示', data.msg);
							$("#pro_bro_datagrid").datagrid('reload');
							$("#pro_bro_datagrid").datagrid('uncheckAll');
						} else {
							parent.$.messager.alert('错误', data.msg);
						}
			}
		});
			}});
	} else {
		parent.$.messager.alert('提示', "请选择需要删除的商品！");
	}
}
function modSubPro(){
	var rows = $("#pro_bro_datagrid").datagrid('getChecked');
	if (rows && rows.length == 1) {
		   $("#pro_mod_dialog").dialog({    
		    title: '修改商品信息',    
		    width: 550,   
		    height: 500,
		    closed: false,    
		    cache: false,
		    iconCls:'icon-edit',
		    href: 'repertory_manager/modProInfoPage?id='+rows[0].id,    
		    modal: true,
		    onClose:function(){
		    	$("#pro_bro_datagrid").datagrid('reload');
		    	$("#pro_bro_datagrid").datagrid('uncheckAll');
		    }  
		});    
	} else {
		parent.$.messager.alert('提示', "请选择一件商品信息！");
		$("#pro_bro_datagrid").datagrid('uncheckAll');
	}
}